<template>
  <div class="app-container">
    <div class="base-container mb-10px flex items-center">
      <div class="total">
        <span>累计乘车订单金额：</span>
        <span class="amount">{{ formatNumberWithCommas(formatAmount(summary.total_fee)) }}</span>
        <span>元</span>
      </div>
      <div class="total">
        <span>累计乘车订单数：</span>
        <span class="amount">{{ formatNumberWithCommas(summary.total_sum) }}</span>
        <span>笔</span>
      </div>
    </div>

    <div class="base-container mb-50px">
      <!-- <el-row :gutter="10" class="mb-10px">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['bus:platOrderPre:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row> -->

      <el-table border v-loading="loading" :data="platOrderPreList" @selection-change="handleSelectionChange">
        <el-table-column label="来源渠道" align="center" prop="channelName" width="150" show-overflow-tooltip />
        <el-table-column label="用户编号" align="center" prop="platformUserId" width="150" show-overflow-tooltip />
        <el-table-column label="手机号码" align="center" prop="mobile" width="120" />
        <el-table-column label="电子卡号" align="center" prop="cardNo" width="150" show-overflow-tooltip />
        <el-table-column label="公司名称" align="center" prop="subCompanyName" width="150" show-overflow-tooltip/>
        <el-table-column label="线路" align="center" prop="lineName" width="120" />
        <el-table-column label="车牌号" align="center" prop="plateNum" width="110" />
        <el-table-column label="票价（元）" align="center" prop="payFee" width="100">
          <template #default="scope">
            <span>{{ formatAmount(scope.row.payFee) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="优惠金额（元）" align="center" prop="couponFee" width="120">
          <template #default="scope">
            <span>{{ formatAmount(scope.row.couponFee) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实扣金额（元）" align="center" prop="actualFee" width="120">
          <template #default="scope">
            <span>{{ scope.row.extTen == 1 || scope.row.extTen == 3 ? '' : formatAmount(scope.row.actualFee) }}</span>
          </template>
        </el-table-column>
        <el-table-column label="支付模式" align="center" prop="payMode">
          <template #default="scope">
            <dict-tag :options="plat_order_pay_mode" :value="scope.row.payMode"/>
          </template>
        </el-table-column>
        <el-table-column label="支付方式" align="center" prop="payChannel" width="100">
          <template #default="scope">
            <dict-tag :options="plat_order_pay_channel" :value="scope.row.payChannel"/>
          </template>
        </el-table-column>
        <el-table-column label="订单状态" align="center" prop="extTen" width="100">
          <template #default="scope">
            <dict-tag :options="ride_order_status" :value="scope.row.extTen"/>
          </template>
        </el-table-column>
        <el-table-column label="扫码时间" align="center" prop="startTime" width="160" />
        <el-table-column label="扣款时间" align="center" prop="payTime" width="160" />
        <el-table-column label="交易流水号" align="center" prop="transactionId" width="150" show-overflow-tooltip />
        <el-table-column label="机具订单编号" align="center" prop="machineOutTradeNo" width="150" show-overflow-tooltip />
        <el-table-column label="商户订单号" align="center" prop="platOrderNo" width="150" show-overflow-tooltip />
        <el-table-column label="对账日期" align="center" prop="extFive" width="120">
          <template #default="scope">
            <span>{{ parseTime(scope.row.extFive, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="支付异常描述" align="center" prop="exDetail" /> -->
        <!-- <el-table-column label="备注" align="center" prop="remark" /> -->
        <!-- <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="100">
          <template #default="scope">
            <el-button link type="primary" icon="View" @click="showOrderDetail(scope.row)" v-hasPermi="['bus:platOrderPre:query']">详情</el-button>
          </template>
        </el-table-column> -->
      </el-table>
    </div>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />

    <Dialog v-model="showDialog" :title="dialogTitle" width="70%">
      <order-detail 
        ref="orderDetail"
        @cancel="showDialog = false"
      />
    </Dialog>
  </div>
</template>

<script setup name="PlatOrderPre">
import { listPlatOrderPre } from "@/api/order/ride"
import { nextTick } from "vue"
import OrderDetail from './detail.vue'

const props = defineProps(['userId', 'platUserId'])
const orderDetail = ref()
const { proxy } = getCurrentInstance()
const { plat_order_pay_mode, plat_order_pay_channel, ride_order_status } = proxy.useDict('plat_order_pay_mode', 'plat_order_pay_channel', 'ride_order_status')

const summary = ref({})
const platOrderPreList = ref([])
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const showDialog = ref(false)
const dialogTitle = ref('乘车订单详情')

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    orderType: 1,   // 按照 start_time进行倒序排列
  }
})

const { queryParams } = toRefs(data)

/** 查询订单列表 */
function getList() {
  loading.value = true
  const data = {
    ...queryParams.value,
    platformUserId: props.platUserId
  }
  listPlatOrderPre(data).then(response => {
    platOrderPreList.value = response.rows
    summary.value = response.remark || {}
    total.value = response.total
    loading.value = false
  })
}

/** 订单详情 */
const showOrderDetail = (row) => {
  showDialog.value = true
  nextTick(() => {
    orderDetail.value.pageInit(row.id)
  })
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('bus/platOrderPre/export', {
    ...queryParams.value
  }, `用户乘车记录_${proxy.getFileImportName()}.xlsx`)
}

getList()
</script>

<style lang="scss" scoped>
.total {
  width: 33.33%;
  color: #606266;
  font-size: 14px;
  padding: 8px 0;

  .amount {
    color: #333;
    font-size: 18px;
    padding-right: 3px;
    font-weight: bold;
  }
}
</style>
